package com.itheima.appserver.controller;

import com.itheima.appserver.service.SettingsService;
import com.itheima.appserver.service.UserService;
import com.itheima.autoconfig.template.SmsTemplate;
import com.itheima.model.vo.PageResult;
import com.itheima.model.vo.SettingsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;
    @Autowired
    private SmsTemplate smsTemplate;
    @Autowired
    private UserService userService;

    @GetMapping("/settings")//通用
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.findById();
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/questions")//陌生人问题
    public ResponseEntity questions(@RequestBody String content) {
        //保存问题
        settingsService.saveQuestions(content);
        return ResponseEntity.ok(null);
    }

    @PostMapping("/notifications/setting")//设置通用开关
    public ResponseEntity notifications(@RequestBody Map map) {
        //调用service直接保存
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }

    //设置黑名单
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "5") int size) {
        //调用service查询分页返回
        PageResult pr = settingsService.pageBlack(page, size);
        //返回数据
        return ResponseEntity.ok(pr);
    }

    //移除黑名单
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId) {
        settingsService.remove(blackUserId);
        return ResponseEntity.ok(null);
    }


}
